numbers = ['zero','one','two','three','four','five','six','seven','eight','nine']
divisors = 0
dif1 = 0
dif2 = 0
p = 0

x = input().split()
n = ''

for i in x:
    if (i in numbers) == False:
        print('Wrong input')
        exit()

if len(x) == 3 and x[0] != 'zero':
    for i in x:
        n += str(numbers.index(i))
else:
    print('Wrong input')
    exit()

n = int(n)

p = n
while True:
    p += 1
    divisors = 0
    for i in range(1, p+1):
        if p % i == 0:
            divisors += 1
    if divisors == 2:
        break
dif1 = p - n
p = n

while True:
    p -= 1
    divisors = 0
    for i in range(1, p+1):
        if p % i == 0:
            divisors += 1
    if divisors == 2:
        break
dif2 = n - p
p = n

if dif2 > dif1:
    print(n + dif1)
elif dif2 < dif1:
    print(n - dif2)
elif dif1 == dif2:
    print(n - dif2)
